package secondwork;

import java.util.Scanner;

/**
 * @author ：chenzikang
 * @date ： 2020/3/7
 */

public class FindByte {
    public static void main(String[] args) {


        findLowEightByte();
        findLowFourByte();


    }

    /**
     * 输入数字即可得到低八位
     */
    public static void findLowEightByte(){
        Scanner scanner  = new Scanner(System.in);
        System.out.println("请输数据");
        int a  = scanner.nextInt();
        int b = a& 0xFF;
        String s = Integer.toBinaryString(b);
        while(s.length() < 8)  s="0" + s;
        System.out.println("低八位为："+s);
    }


    /**
     * 输入数字即可得到低四位
     */
    public static void findLowFourByte(){
        Scanner scanner  = new Scanner(System.in);
        System.out.println("请输数据");
        int a  = scanner.nextInt();
        int b = a& 0xF;
        String s = Integer.toBinaryString(b);
        while(s.length() < 4)  s="0" + s;
        System.out.println("低四位为："+s);
    }

}
